package cc.zyjx.web.controller.school;

import cc.zyjx.common.annotation.Log;
import cc.zyjx.common.core.controller.BaseController;
import cc.zyjx.common.core.domain.AjaxResult;
import cc.zyjx.common.core.page.TableDataInfo;
import cc.zyjx.common.enums.BusinessType;
import cc.zyjx.common.utils.poi.ExcelUtil;
import cc.zyjx.school.domain.TrClassTpye;
import cc.zyjx.school.service.ITrClassTpyeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 学员班级Controller
 *
 * @author 座山客
 * @date 2023-05-02
 */
@RestController
@RequestMapping("/school/tpye")
public class TrClassTpyeController extends BaseController {
    @Autowired
    private ITrClassTpyeService trClassTpyeService;

    /**
     * 查询学员班级列表
     */
    @PreAuthorize("@ss.hasPermi('school:tpye:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrClassTpye trClassTpye) {
        startPage();
        List<TrClassTpye> list = trClassTpyeService.selectTrClassTpyeList(trClassTpye);
        return getDataTable(list);
    }

    /**
     * 导出学员班级列表
     */
    @PreAuthorize("@ss.hasPermi('school:tpye:export')")
    @Log(title = "学员班级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrClassTpye trClassTpye) {
        List<TrClassTpye> list = trClassTpyeService.selectTrClassTpyeList(trClassTpye);
        ExcelUtil<TrClassTpye> util = new ExcelUtil<TrClassTpye>(TrClassTpye.class);
        util.exportExcel(response, list, "学员班级数据");
    }

    /**
     * 获取学员班级详细信息
     */
    @PreAuthorize("@ss.hasPermi('school:tpye:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(trClassTpyeService.selectTrClassTpyeById(id));
    }

    /**
     * 新增学员班级
     */
    @PreAuthorize("@ss.hasPermi('school:tpye:add')")
    @Log(title = "学员班级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrClassTpye trClassTpye) {
        return toAjax(trClassTpyeService.insertTrClassTpye(trClassTpye));
    }

    /**
     * 修改学员班级
     */
    @PreAuthorize("@ss.hasPermi('school:tpye:edit')")
    @Log(title = "学员班级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrClassTpye trClassTpye) {
        return toAjax(trClassTpyeService.updateTrClassTpye(trClassTpye));
    }

    /**
     * 删除学员班级
     */
    @PreAuthorize("@ss.hasPermi('school:tpye:remove')")
    @Log(title = "学员班级", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(trClassTpyeService.deleteTrClassTpyeByIds(ids));
    }
}
